#include "HealthBar.h"


HealthBar::HealthBar(void)
{
	_healthSprite = NULL;
}


HealthBar::~HealthBar(void)
{
}

bool HealthBar::init()
{
	if (!CCNode::init())
		return false;

	CCSprite* total = CCSprite::createWithSpriteFrameName("health_bar_1.png");
	total->setAnchorPoint(CCPointZero);
	addChild(total);

	CCSprite* health = CCSprite::createWithSpriteFrameName("health_bar_2.png");
	health->setAnchorPoint(CCPointZero);
	health->setPosition(ccp(4,5));
	addChild(health);
	setHealthSprite(health);

	this->setContentSize(total->getContentSize());

	return true;
}

float HealthBar::getPercent()
{
	return _percent;
}

void HealthBar::setPercent(float var)
{
	if (var < 0)
		var = 0;
	if (var > 1)
		var = 1;
	_percent = var;
	getHealthSprite()->setScaleX(_percent);
}